" Vim filetype plugin
" Language:   LessCSS
" Author:     Naoyuki ABE <plasticscafe@gmail.com>
" md by:      tangoboy <tangoboyzhulu@gmail.com>
" Last Change: 2011 Dec 7


if !exists('g:less_autocompile')
  let g:less_autocompile = 0
endif


autocmd BufWritePost *.less call s:auto_less_compile()


function! s:auto_less_compile()
  if g:less_autocompile != 0
    try
      let css_name = expand("%:r") . ".css"
      let less_name = expand("%")
      let options = ' --tsdk '
      
      if filereadable(css_name) || 0 < getfsize(less_name)
        let cmd = ':!lessc '.options.' '.less_name.' '.css_name
        silent execute cmd

        "let less_date = system('date -r ' . less_name . ' +%s')
        "let css_date = system('date -r ' . css_name . ' +%s')
        "if !filereadable(css_name) || css_date < less_date
        "  highlight StatusLine ctermfg=Red
        "else
        "  highlight StatusLine ctermfg=none
        "endif
      endif
    endtry
  endif
endfunction
